package com.styytech.dadabao.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.styytech.dadabao.R;
import com.styytech.dadabao.bean.MyMessage;
import com.styytech.dadabao.ui.more.NoticeDetailsActivity;

import java.util.LinkedList;

/**
 * 服务公告适配器.
 */
public class MyMessageItemAdapter extends BaseAdapter {

    private LinkedList<Object> mList = null;
    private LayoutInflater mInflater = null;
    ViewHolder holder = null;
    private Context mContext;

    public MyMessageItemAdapter(LinkedList<Object> mList, Context context) {
        this.mList = mList;
        this.mContext = context;
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    }

    @Override
    public int getCount() {
        if (mList == null) {
            return 0;
        }
        return mList.size();
    }

    @Override
    public Object getItem(int arg0) {
        return null;
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup arg2) {
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(
                    R.layout.item_notice_record, null);
            holder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            holder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
            holder.tv_content = (TextView) convertView.findViewById(R.id.tv_content);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Object obj = mList.get(position);
        final MyMessage itemData = (MyMessage) obj;
        final String title = itemData.getTitle();
        final String time = itemData.getCreateTime();
        final String content = itemData.getMessageContent();
        final int status = itemData.getStatus();
        holder.tv_title.setText(title);
        holder.tv_time.setText(time);
        holder.tv_content.setText(content);

        convertView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                //点击单个条目
                Intent intent = new Intent();
                intent.setClass(mContext, NoticeDetailsActivity.class);
                intent.putExtra("BEAN", itemData);
                mContext.startActivity(intent);
            }
        });


        return convertView;
    }

    private class ViewHolder {
        private TextView tv_title;
        private TextView tv_time;
        private TextView tv_content;


    }
}
